package com.kaiyun.sharding;

import com.kaiyun.sharding.mapper.DictionaryMapper;
import com.kaiyun.sharding.mapper.UserMapper;
import com.kaiyun.sharding.model.Dictionary;
import com.kaiyun.sharding.model.User;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 测试专库专表
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class ShardingApplicationTests3 {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DictionaryMapper dictionaryMapper;


    /**
     * 插入专库专表
     */
    @Test
    public void insertOneUser() {
        for (int i = 0; i <10 ; i++) {
            User cc=new User();
            cc.setName("姓名112d"+i);
            cc.setAge(i);
            userMapper.insert(cc);
        }
    }


    /**
     * 插入公共表
     */
    @Test
    public void insertOneDictionary() {
        for (int i = 0; i <10 ; i++) {
            Dictionary dy=new Dictionary();
            dy.setName("测试"+i);
            dy.setUserId(1L);
            dy.setCode("0000");
            dictionaryMapper.insert(dy);
        }
    }

    /**
     * 删除公共表
     */
    @Test
    public void delete() {
        dictionaryMapper.deleteById(1333324931080433666L);
    }



}
